"""
日志处理工具类
"""
import sys
from loguru import logger
from api_test_framework.config.settings import LOG_CONFIG
from api_test_framework.utils.handle_path import PathHandler

def init_logger():
    """
    初始化日志配置
    """
    # 清除默认处理器
    logger.remove()
    
    # 添加控制台输出
    logger.add(
        sys.stdout,
        level=LOG_CONFIG["level"],
        format="<green>{time:YYYY-MM-DD HH:mm:ss}</green> | "
               "<level>{level: <8}</level> | "
               "<cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - "
               "<level>{message}</level>"
    )
    
    # 添加文件输出
    logger.add(
        PathHandler.LOG_DIR / LOG_CONFIG["file_path"],
        level=LOG_CONFIG["level"],
        rotation=LOG_CONFIG["rotation"],
        retention=LOG_CONFIG["retention"],
        encoding="utf-8"
    )
    
    return logger 